home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / mobile / fma-2.0-stable-setup.exe / {app} / source / uComposeSMS.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2004-12-09  |  19.4 KB  |  647 lines

  1. unit uComposeSMS;
  2.  
  3. {
  4. *******************************************************************************
  5. * Descriptions: Implementation for SMS Editor Dialog
  6. * $Source: /cvsroot/fma/fma/uComposeSMS.pas,v $
  7. * $Locker:  $
  8. *
  9. * Todo:
  10. *
  11. * Change Log:
  12. * $Log: uComposeSMS.pas,v $
  13. * Revision 1.18.6.2  2004/12/09 12:38:46  z_stoichev
  14. * Bug 1073298 SMS text input move cursor at the end.
  15. *
  16. * Revision 1.18.6.1  2004/10/15 11:27:58  z_stoichev
  17. * Bugfixes
  18. *
  19. * Revision 1.18  2004/08/19 12:55:31  merijnb
  20. * contents of sms textbox aren't cleared if the sms compose window was already visible (1003202)
  21. *
  22. * Revision 1.17  2004/07/26 12:51:53  z_stoichev
  23. * Force UCS-2 support
  24. * Status bar popup menu
  25. * Initial view update fixes
  26. *
  27. * Revision 1.16  2004/06/29 12:37:06  z_stoichev
  28. * New message window renamed
  29. *
  30. * Revision 1.15  2004/06/28 15:27:23  z_stoichev
  31. * Move Favorites to phone profile.
  32. *
  33. * Revision 1.14  2004/06/23 13:46:34  z_stoichev
  34. * Chat support
  35. *
  36. * Revision 1.13  2004/06/19 11:16:36  z_stoichev
  37. * - Fixed New Message toolbars size.
  38. * - Fixed Do not add groups as new contact.
  39. *
  40. * Revision 1.12  2004/05/19 18:34:15  z_stoichev
  41. * Build 0.1.0.35c
  42. *
  43. * Revision 1.11  2004/04/01 15:02:35  z_stoichev
  44. * GUI changes
  45. * Reset conter menu
  46. *
  47. * Revision 1.10  2004/03/26 18:37:39  z_stoichev
  48. * Build 0.1.0.35 RC5
  49. *
  50. * Revision 1.9  2004/03/12 16:57:13  z_stoichev
  51. * Fixed Long SMS refference number auto-increment.
  52. *
  53. * Revision 1.8  2004/01/15 14:13:56  z_stoichev
  54. * Added SMS Counter and Warning level.
  55. *
  56. * Revision 1.7  2003/12/17 16:45:36  z_stoichev
  57. * Alow save draft on recepient change.
  58. *
  59. * Revision 1.6  2003/12/16 17:38:38  z_stoichev
  60. * Add support for contacts without numbers.
  61. *
  62. * Revision 1.5  2003/11/28 09:38:07  z_stoichev
  63. * Merged with branch-release-1-1 (Fma 0.10.28c)
  64. *
  65. * Revision 1.4.2.4  2003/11/27 16:04:36  z_stoichev
  66. * Add save draft button.
  67. *
  68. * Revision 1.4.2.3  2003/11/10 14:03:09  z_stoichev
  69. * RC3
  70. *
  71. * Revision 1.4.2.2  2003/10/29 16:24:13  z_stoichev
  72. * Add Groups support.
  73. * Status Report support detected from phone.
  74. *
  75. * Revision 1.4.2.1  2003/10/27 07:22:54  z_stoichev
  76. * Build 0.1.0 RC1 Initial Checkin.
  77. *
  78. * Revision 1.4  2003/10/23 11:34:02  z_stoichev
  79. * Fixed bug when sending Long sms with Flash on.
  80. * Toolbar customize disabled on dbl click.
  81. * Icons rearranged, and font changed.
  82. *
  83. * Revision 1.3  2003/10/21 08:52:51  z_stoichev
  84. * Using SelContacts property from AddressBook.
  85. *
  86. * Revision 1.2  2003/10/14 12:20:42  z_stoichev
  87. * Use address book to select recipients.
  88. * Fixed drag and drop from explorer.
  89. * Select entire recipient address on click
  90. * in edit box.
  91. *
  92. * Revision 1.1  2003/10/14 09:26:28  z_stoichev
  93. * Unit SentSMS renamed to uComposeSMS.
  94. *
  95. * Revision 1.5  2003/02/14 07:12:56  crino77
  96. *   10/02/2003 - Modified by Crino
  97. *      Added Long SMS support;
  98. *
  99. * Revision 1.4  2003/02/13 08:22:19  crino77
  100. * Test
  101. *
  102. * Revision 1.3  2003/01/30 04:15:57  warren00 crino77
  103. * Updated with header comments
  104. *
  105. *
  106. *******************************************************************************
  107. }
  108.  
  109. interface
  110.  
  111. uses
  112.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  113.   Dialogs, StdCtrls, ComCtrls, ToolWin, ImgList, Placemnt, 
  114.   Buttons, TntStdCtrls, ExtCtrls, Menus, Registry;
  115.  
  116. const
  117.   MaxFavorites = 20;
  118.  
  119. type
  120.   TfrmMessageContact = class(TForm)
  121.     CoolBar1: TCoolBar;
  122.     ToolBar1: TToolBar;
  123.     StatusBar: TStatusBar;
  124.     FormPlacement1: TFormPlacement;
  125.     Memo: TTntMemo;
  126.     ToolBar2: TToolBar;
  127.     WarningPanel: TPanel;
  128.     Panel1: TPanel;
  129.     Image1: TImage;
  130.     lbWarning: TLabel;
  131.     FavoritesPopupMenu: TPopupMenu;
  132.     btnSend: TToolButton;
  133.     ToolButton8: TToolButton;
  134.     ToolButton5: TToolButton;
  135.     ToolButton9: TToolButton;
  136.     btnStatusReport: TToolButton;
  137.     btnRequestReply: TToolButton;
  138.     ToolButton1: TToolButton;
  139.     btnSave: TToolButton;
  140.     btnLongSMS: TToolButton;
  141.     btnFlashSMS: TToolButton;
  142.     btnRecent: TToolButton;
  143.     ToolButton6: TToolButton;
  144.     PopupMenu2: TPopupMenu;
  145.     ClearMessageCounter1: TMenuItem;
  146.     ToPopupMenu: TPopupMenu;
  147.     Add1: TMenuItem;
  148.     N1: TMenuItem;
  149.     Delete1: TMenuItem;
  150.     AddToPhonebook1: TMenuItem;
  151.     AddToFavorites1: TMenuItem;
  152.     Organize1: TMenuItem;
  153.     N2: TMenuItem;
  154.     btnTo: TToolButton;
  155.     N3: TMenuItem;
  156.     Edit1: TTntEdit;
  157.     EncodingPopupMenu1: TPopupMenu;
  158.     ForceUCS2Encoding1: TMenuItem;
  159.     DoStrictUCS2Check1: TMenuItem;
  160.     procedure SendClick(Sender: TObject);
  161.     procedure MemoChange(Sender: TObject);
  162.     procedure Edit1DragOver(Sender, Source: TObject; X, Y: Integer;
  163.       State: TDragState; var Accept: Boolean);
  164.     procedure Edit1DragDrop(Sender, Source: TObject; X, Y: Integer);
  165.     procedure ClearClick(Sender: TObject);
  166.     procedure MemoKeyPress(Sender: TObject; var Key: Char);
  167.     procedure FormShow(Sender: TObject);
  168.     procedure LongClick(Sender: TObject);
  169.     procedure ToolBar2Resize(Sender: TObject);
  170.     procedure ToClick(Sender: TObject);
  171.     procedure Edit1Click(Sender: TObject);
  172.     procedure SaveClick(Sender: TObject);
  173.     procedure Edit1Change(Sender: TObject);
  174.     procedure FormActivate(Sender: TObject);
  175.     procedure PopupMenu1Click(Sender: TObject);
  176.     procedure FavoritesPopupMenuPopup(Sender: TObject);
  177.     procedure btnRecentClick(Sender: TObject);
  178.     procedure ClearMessageCounter1Click(Sender: TObject);
  179.     procedure PopupMenu2Popup(Sender: TObject);
  180.     procedure ToPopupMenuPopup(Sender: TObject);
  181.     procedure Delete1Click(Sender: TObject);
  182.     procedure AddToPhonebook1Click(Sender: TObject);
  183.     procedure AddToFavorites1Click(Sender: TObject);
  184.     procedure Organize1Click(Sender: TObject);
  185.     procedure UCS2Click(Sender: TObject);
  186.     procedure EncodingPopupMenu1Popup(Sender: TObject);
  187.   private
  188.     { Private declarations }
  189.     FMaxLength: Integer;
  190.     procedure DoSend(AsDraft: boolean = False);
  191.   protected
  192.     FChatMode: boolean;
  193.   public
  194.     { Public declarations }
  195.     procedure AddRecipient(node: TTreeNode); overload;
  196.     procedure AddRecipient(str: String); overload;
  197.     procedure Clear;
  198.   end;
  199.  
  200. var
  201.   frmMessageContact: TfrmMessageContact;
  202.  
  203. implementation
  204.  
  205. uses Unit1, gsm_sms, TntComCtrls, uSelectContact;
  206.  
  207. {$R *.dfm}
  208.  
  209. procedure TfrmMessageContact.MemoChange(Sender: TObject);
  210. var
  211.   len, packetCount, packetL: Integer;
  212. begin
  213.   if ForceUCSusage or (CheckCodingType(Memo.Text) = 2) then begin
  214.     StatusBar.Panels[1].Text := 'UCS-2';
  215.     FMaxLength := 70;
  216.   end
  217.   else if CheckCodingType(Memo.Text) = 1 then begin
  218.     StatusBar.Panels[1].Text := '8-bit';
  219.     FMaxLength := 140;
  220.   end
  221.   else begin
  222.     StatusBar.Panels[1].Text := '';
  223.     FMaxLength := 160;
  224.   end;
  225.  
  226.   if btnLongSMS.Down then begin
  227.      packetL := (FMaxLength - 7);
  228.      len := length(Memo.Text);
  229.      packetCount := (len div packetL) + 1;
  230.      if len <= FMaxLength then packetCount := 1;
  231.      StatusBar.Panels[0].Text := 'SMS: ' + IntToStr(packetCount);
  232.      StatusBar.Panels[0].Text := StatusBar.Panels[0].Text + ' - chars ' + IntToStr(length(Memo.Text));
  233.      // Enable Flash only on simple SMS.
  234.      // btnFlashSMS.Enabled := packetCount = 1;
  235.   end
  236.   else begin
  237.      Memo.MaxLength := FMaxLength;
  238.      len := length(Memo.Text);
  239.      if len > FMaxLength then begin
  240.        Memo.Text := Copy(Memo.Text,1,FMaxLength);
  241.        Memo.SelStart := len;
  242.        len := FMaxLength;
  243.      end;
  244.      StatusBar.Panels[0].Text := IntToStr(Memo.MaxLength - len) + ' char left';
  245.      btnFlashSMS.Enabled := True;
  246.   end;
  247.  
  248.   btnSave.Enabled := memo.Text <> '';
  249. end;
  250.  
  251. procedure TfrmMessageContact.Edit1DragOver(Sender, Source: TObject; X, Y: Integer;
  252.   State: TDragState; var Accept: Boolean);
  253. var
  254.   node: TTreeNode;
  255. begin
  256.   Accept := False;
  257.  
  258.   if Source is TTntTreeView then begin
  259.     node := (Source As TTntTreeView).Selected;
  260.     if (node.ImageIndex >= 9) and (node.ImageIndex <= 13) then Accept := True;
  261.   end;
  262. end;
  263.  
  264. procedure TfrmMessageContact.Edit1DragDrop(Sender, Source: TObject; X,
  265.   Y: Integer);
  266. begin
  267.   if Source is TTntTreeView then AddRecipient((Source As TTntTreeView).Selected);
  268. end;
  269.  
  270. procedure TfrmMessageContact.ClearClick(Sender: TObject);
  271. begin
  272.   Clear;
  273. end;
  274.  
  275. procedure TfrmMessageContact.AddRecipient(node: TTreeNode);
  276. var
  277.   str: String;
  278. begin
  279.   str := node.Parent.Text + ' [' + node.Text + ']';
  280.  
  281.   if trim(Edit1.Text) <> '' then Edit1.Text := trim(Edit1.Text) + '; ';
  282.   Edit1.Text := Edit1.Text + str;
  283. end;
  284.  
  285. procedure TfrmMessageContact.AddRecipient(str: String);
  286. begin
  287.   Edit1.Text := str;
  288. end;
  289.  
  290. procedure TfrmMessageContact.Clear;
  291. begin
  292.   Memo.Lines.Clear;
  293.   Edit1.Text := '';
  294.   StatusBar.Panels[0].Text := '';
  295.   StatusBar.Panels[1].Text := '';
  296.   btnSave.Enabled := False;
  297. end;
  298.  
  299.  
  300. procedure TfrmMessageContact.MemoKeyPress(Sender: TObject; var Key: Char);
  301. begin
  302.   if ord(Key) = 10 then btnSend.Click; // Ctrl-Enter Sent
  303. end;
  304.  
  305. procedure TfrmMessageContact.FormShow(Sender: TObject);
  306. begin
  307.   try
  308.     btnStatusReport.Enabled := Form1.FStatusReport;
  309.     if btnStatusReport.Enabled then
  310.       btnStatusReport.Hint := 'Request Status Report'
  311.     else
  312.       btnStatusReport.Hint := 'Not supported by phone';
  313.     btnFlashSMS.Enabled := True;
  314.     btnSave.Enabled := False;
  315.     if Edit1.Text = '' then Edit1.SetFocus else
  316.       Memo.SetFocus;
  317.     CoolBar1.Bands[0].MinHeight := 36;
  318.     CoolBar1.Bands[1].MinHeight := 22;
  319.     Memo.Clear();
  320.   except
  321.   end;
  322. end;
  323.  
  324. procedure TfrmMessageContact.ToolBar2Resize(Sender: TObject);
  325. begin
  326.   Edit1.Width := ToolBar2.Width - btnTo.Width - btnRecent.Width - 4;
  327. end;
  328.  
  329. procedure TfrmMessageContact.ToClick(Sender: TObject);
  330. begin
  331.   with TfrmSelContact.Create(nil) do
  332.   try
  333.     SelContacts := Edit1.Text;
  334.     if ShowModal = mrOk then
  335.       Edit1.Text := SelContacts;
  336.   finally
  337.     Free;
  338.   end;
  339. end;
  340.  
  341. procedure TfrmMessageContact.Edit1Click(Sender: TObject);
  342. var
  343.   a,b: string;
  344.   i,j: integer;
  345.   p,r: pchar;
  346. begin
  347.   a := Copy(Edit1.Text,1,Edit1.SelStart);
  348.   b := Edit1.Text;
  349.   Delete(b,1,Edit1.SelStart);
  350.   i := 1;
  351.   if a <> '' then begin
  352.     p := @a[1];
  353.     r := AnsiStrRScan(p,';');
  354.     if r <> nil then begin
  355.       i := r-p+2;
  356.       while (i < length(a)) and (a[i] = ' ') do inc(i); 
  357.     end;
  358.   end;
  359.   j := Length(b);
  360.   if b <> '' then begin
  361.     p := @b[1];
  362.     r := AnsiStrScan(p,';');
  363.     if r <> nil then j := r-p+1;
  364.   end;
  365.   with Edit1 do begin
  366.     SelStart := i-1;
  367.     SelLength := length(a)-i+1+j;
  368.   end;
  369. end;
  370.  
  371. procedure TfrmMessageContact.DoSend(AsDraft: boolean);
  372. var
  373.   str, smsRef: String;
  374.   it,sl: TStringList;
  375.   k, i, j, s, startpos, stoppos, dcs: Integer;
  376.   group,complex: Boolean;
  377.   text, temp: WideString;
  378.  
  379.   smstot,udhi:string;
  380.   packetL: Integer;
  381. begin
  382.   sl := TStringList.Create;
  383.   try
  384.     str := '';
  385.  
  386.     for i := 1 to length(Edit1.Text) do begin
  387.       if not IsDelimiter(';', Edit1.Text, i) then str := str + Edit1.Text[i]
  388.       else begin
  389.         if trim(str) <> '' then sl.Add(trim(str));
  390.         str := '';
  391.       end;
  392.  
  393.       if i = length(Edit1.Text) then
  394.         if trim(str) <> '' then sl.Add(trim(str));
  395.     end;
  396.  
  397.     if sl.Count = 0 then raise Exception.Create('You have to select at least one recepient');
  398.  
  399.     for i := 0 to sl.Count-1 do begin
  400.       group := False;
  401.       complex := False;
  402.       for j := 1 to length(sl.Strings[i]) do begin
  403.         if IsDelimiter('[]', sl.Strings[i], j) then complex := True;
  404.         if IsDelimiter('{}', sl.Strings[i], j) then group := True;
  405.       end;
  406.  
  407.       if group then begin
  408.         startpos := pos('{', sl.Strings[i]);
  409.         stoppos := pos('}', sl.Strings[i]);
  410.  
  411.         { make sure it will have at least one element }
  412.         if (startpos = 0) or (stoppos < (startpos+2)) then raise Exception.Create('Invalid Group Address');
  413.  
  414.         sl.Strings[i] := copy(sl.Strings[i], startpos + 1, stoppos - startpos - 1);
  415.  
  416.         it := TStringList.Create;
  417.         try
  418.           it.CommaText := sl.Strings[i];
  419.           { convert all from names to numbers }
  420.           for k := 0 to it.Count-1 do
  421.             it[k] := Form1.LookupNumber(it[k]);
  422.           { sanity check }  
  423.           for k := 0 to it.Count-1 do
  424.             for j := 1 to length(it[k]) do
  425.               if not isDelimiter('+0123456789', it[k], j) then
  426.                 raise Exception.Create('Invalid Number');
  427.           { replace group with first memeber }
  428.           sl.Strings[i] := it[0];
  429.           { then add others at the end of list. it's safe to do that
  430.             since these number don't have to be checked out. }
  431.           for k := 1 to it.Count-1 do
  432.             sl.Add(it[k]);
  433.         finally
  434.           it.free;
  435.         end;
  436.       end
  437.       else
  438.       if complex then begin
  439.         startpos := pos('[', sl.Strings[i]);
  440.         stoppos := pos(']', sl.Strings[i]);
  441.  
  442.         { make sure it will have at least one element }
  443.         if (startpos = 0) or (stoppos < (startpos+2)) then raise Exception.Create('Invalid Address');
  444.  
  445.         sl.Strings[i] := copy(sl.Strings[i], startpos + 1, stoppos - startpos - 1);
  446.  
  447.         for j := 1 to length(sl.Strings[i]) do
  448.           if not isDelimiter('+0123456789', sl.Strings[i], j) then
  449.             raise Exception.Create('Invalid Number');
  450.       end
  451.       else begin
  452.         { Check if we have contact instead of number }
  453.         str := Form1.LookupNumber(sl.Strings[i]);
  454.         if str <> '' then sl.Strings[i] := str;
  455.       end;
  456.     end;
  457.  
  458.     Text := Memo.Text;
  459.     dcs := -1;
  460.  
  461.     {TEST LONG}
  462.     if btnLongSMS.Down then begin
  463.        if length(Text) <= FMaxLength then begin
  464.           //sending normal SMS in long SMS mode...
  465.           for i := 0 to sl.Count - 1 do begin
  466.              StatusBar.Panels[2].Text := 'Sending message to ' + sl.Strings[i] + '...';
  467.              Form1.SentMessage('', Text, sl.Strings[i], btnRequestReply.Down, btnFlashSMS.Down, btnStatusReport.Down,
  468.                dcs, AsDraft);
  469.           end;
  470.        end
  471.        else begin
  472.          //sending Long SMS...
  473.          packetL := (FMaxLength - 7);
  474.          smstot := IntToHex((length(Text) div packetL) + 1, 2);
  475.          //for all recepients...
  476.          for i := 0 to sl.Count - 1 do begin
  477.             StatusBar.Panels[2].Text := 'Sending long message to ' + sl.Strings[i] + '...';
  478.             //...create the sms ref...
  479.             smsRef := Form1.GetNextLongSMSRefference;
  480.             udhi := '050003' + smsRef + smsTot; // see docs for 050003 magic
  481.             //...and send sms segments
  482.             Text := Memo.Text;
  483.             for s := 1 to StrToInt('$' + smstot) do begin
  484.               Temp := Copy(Text, 1, packetL);
  485.               Delete(Text, 1, packetL);
  486.               Form1.SentMessage(udhi + IntToHex(s, 2), Temp, sl.Strings[i], btnRequestReply.Down, btnFlashSMS.Down,
  487.                 btnStatusReport.Down, dcs, AsDraft);
  488.              end;
  489.           end;
  490.        end;
  491.     end
  492.     else begin
  493.        //normal SMS...
  494.        for i := 0 to sl.Count - 1 do begin
  495.           StatusBar.Panels[2].Text := 'Sending message to ' + sl.Strings[i] + '...';
  496.           Form1.SentMessage('', Text, sl.Strings[i], btnRequestReply.Down, btnFlashSMS.Down, btnStatusReport.Down,
  497.             dcs, AsDraft);
  498.        end;
  499.     end;
  500.   finally
  501.     sl.Free;
  502.     if AsDraft then
  503.       StatusBar.Panels[2].Text := Format('Total messages sent: %d',[Form1.FSMSCounter]); // we're not sending actualy
  504.     if FChatMode then
  505.       StatusBar.Panels[2].Text := 'Sending message...'; // the recipient is well-known so dont show it
  506.   end;
  507.   { Close window is sending as normal SMS } 
  508.   if not AsDraft and not FChatMode then
  509.     Close;
  510. end;
  511.  
  512. procedure TfrmMessageContact.SendClick(Sender: TObject);
  513. begin
  514.   DoSend;
  515. end;
  516.  
  517. procedure TfrmMessageContact.SaveClick(Sender: TObject);
  518. begin
  519.   DoSend(True);
  520.   btnSave.Enabled := False;
  521. end;
  522.  
  523. procedure TfrmMessageContact.Edit1Change(Sender: TObject);
  524. begin
  525.   btnSave.Enabled := memo.Text <> '';
  526. end;
  527.  
  528. procedure TfrmMessageContact.FormActivate(Sender: TObject);
  529. begin
  530.   StatusBar.Panels[2].Text := Format('Total messages sent: %d',[Form1.FSMSCounter]);
  531.   WarningPanel.Visible := Form1.FSMSDoWarning and (Form1.FSMSCounter >= Form1.FSMSWarning);
  532.   if WarningPanel.Visible then begin
  533.     if not FChatMode then
  534.       Memo.Top := WarningPanel.Top + WarningPanel.Height;
  535.     lbWarning.Caption := Format('Warning! You have reached your send limit of %d messages.',[Form1.FSMSWarning]);
  536.   end;
  537.   ToolBar2Resize(nil);
  538. end;
  539.  
  540. procedure TfrmMessageContact.PopupMenu1Click(Sender: TObject);
  541. begin
  542.   AddRecipient((Sender as TMenuItem).Caption);
  543. end;
  544.  
  545. procedure TfrmMessageContact.FavoritesPopupMenuPopup(Sender: TObject);
  546. var
  547.   i: integer;
  548.   Item: TMenuItem;
  549. begin
  550.   AddToFavorites1.Enabled := Edit1.Text <> '';
  551.   while FavoritesPopupMenu.Items.Count > 3 do
  552.     FavoritesPopupMenu.Items.Delete(3);
  553.   for i := 0 to Form1.FFavoriteRecipients.Count-1 do begin
  554.     Item := TMenuItem.Create(FavoritesPopupMenu);
  555.     Item.Caption := Form1.FFavoriteRecipients[i];
  556.     Item.AutoHotkeys := maManual;
  557.     Item.ImageIndex := 26;
  558.     Item.OnClick := PopupMenu1Click;
  559.     FavoritesPopupMenu.Items.Add(Item);
  560.   end;
  561. end;
  562.  
  563. procedure TfrmMessageContact.btnRecentClick(Sender: TObject);
  564. begin
  565.   btnRecent.CheckMenuDropdown;
  566. end;
  567.  
  568. procedure TfrmMessageContact.ClearMessageCounter1Click(Sender: TObject);
  569. begin
  570.   Form1.FSMSCounter := 0;
  571.   FormActivate(nil);
  572. end;
  573.  
  574. procedure TfrmMessageContact.PopupMenu2Popup(Sender: TObject);
  575. begin
  576.   ClearMessageCounter1.Enabled := Form1.FSMSCounter <> 0;
  577. end;
  578.  
  579. procedure TfrmMessageContact.LongClick(Sender: TObject);
  580. var
  581.   IsDown: boolean;
  582. begin
  583.   IsDown := btnLongSMS.Down;
  584.   if IsDown and (length(Memo.Text) > FMaxLength) then begin
  585.     btnLongSMS.Down := False; // hack buggy Toolbar
  586.     btnLongSMS.Down := True;
  587.     MessageBeep(MB_ICONQUESTION);
  588.     if MessageDlg('This will crop some text from the end of the current message?',
  589.       mtConfirmation,[mbOk,mbCancel],0) <> mrOk then 
  590.       exit;
  591.   end;
  592.   btnLongSMS.Down := not IsDown;
  593.   if btnLongSMS.Down then
  594.      Memo.MaxLength := 0
  595.   else
  596.      Memo.MaxLength := FMaxLength;
  597.   MemoChange(nil);
  598. end;
  599.  
  600. procedure TfrmMessageContact.ToPopupMenuPopup(Sender: TObject);
  601. begin
  602.   Delete1.Enabled := Edit1.SelText <> '';
  603.   AddToPhonebook1.Enabled := Delete1.Enabled and (Pos('{',Edit1.SelText) = 0) and
  604.     (Form1.LookupContact(Form1.ExtractNumber(Edit1.SelText)) = '');
  605. end;
  606.  
  607. procedure TfrmMessageContact.Delete1Click(Sender: TObject);
  608. begin
  609.   Edit1.SelText := '';
  610. end;
  611.  
  612. procedure TfrmMessageContact.AddToPhonebook1Click(Sender: TObject);
  613. begin
  614.   if Form1.frmSyncPhonebook.DoEdit(True,Form1.ExtractNumber(Edit1.SelText)) then
  615.     Edit1.SelText := Form1.ContactNumberByTel(Form1.ExtractNumber(Edit1.SelText));
  616. end;
  617.  
  618. procedure TfrmMessageContact.AddToFavorites1Click(Sender: TObject);
  619. begin
  620.   if Form1.FFavoriteRecipients.IndexOf(Edit1.Text) = -1 then begin
  621.     Form1.FFavoriteRecipients.Insert(0,Edit1.Text);
  622.     while Form1.FFavoriteRecipients.Count > MaxFavorites do
  623.       Form1.FFavoriteRecipients.Delete(MaxFavorites);
  624.   end;
  625. end;
  626.  
  627. procedure TfrmMessageContact.Organize1Click(Sender: TObject);
  628. begin
  629.   Form1.EditFavorites1.Click;
  630. end;
  631.  
  632. procedure TfrmMessageContact.UCS2Click(Sender: TObject);
  633. begin
  634.   with Sender as TMenuitem do Checked := not Checked; 
  635.   ForceUCSusage := ForceUCS2Encoding1.Checked;
  636.   DoStrictUCScheck := DoStrictUCS2Check1.Checked;
  637.   MemoChange(Memo);
  638. end;
  639.  
  640. procedure TfrmMessageContact.EncodingPopupMenu1Popup(Sender: TObject);
  641. begin
  642.   ForceUCS2Encoding1.Checked := ForceUCSusage;
  643.   DoStrictUCS2Check1.Checked := DoStrictUCScheck;
  644. end;
  645.  
  646. end.
  647.